<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
    <div class="row">

        <div class="col-lg-12">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">所有会议</h3>
                </div>
                <div class="panel-body">
                    
                    <div class="table-responsive">
                        <table id="meeting_all_table"></table>
                        <div id="meeting_all_page"></div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script>

    $(function(){

        init_grid_meeting();

    });

    function init_grid_meeting() {

        __init_jqgrid('meeting_all_table', 'meeting_all_page',
                '<%=path%>/com/meeting/listView?viewtype=${viewtype}',
                ['会议名称', '会议地点', '开始日期', '会议负责人', '会议状态', '操作', 'id'],
                [
                    {name: 'name', index: 'name',width:40, sortable: true, searchoptions: {sopt: ['cn']}},
                    {name: 'address', index: 'address', width: 40, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'datStart', index: 'datStart', width: 60, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'chief', index: 'chief', width: 60, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'txtStatus', index: 'txtStatus', width: 40, sortable: true, search: true, searchoptions: {sopt: ['cn']}},
                    {name: 'act', index: 'act', width: 300, fixed: true, sortable: false, search: false, formatter: actFormat},
                    {name: 'id', index: 'id', width: 100, key: true, hidden: true, hidedlg: true}
                ],
                true,true
        );

    }

    function actFormat(cellvalue, options, rowObject){
        var id = rowObject.id;
        var cancel=rowObject.txtStatus;
        cellvalue = '<button class="btn btn-white btn-sm" data-original-title="查看" onclick="fn_meeting_read(\'' + id + '\');"><i class="fa fa-eye"> </i> 查看</button> ';
        if(cancel!="流转中") {
            if (cancel != "已取消") {
                cellvalue += '<button class="btn btn-white btn-sm" data-original-title="会议取消" onclick="fn_meeting_cancel(\'' + id + '\');"><i class="fa fa-eye"> </i> 会议取消</button> ';
            }
            cellvalue += '<button class="btn btn-white btn-sm" data-original-title="会议调整" onclick="fn_meeting_update(\'' + id + '\');"><i class="fa fa-eye"> </i> 会议调整</button> ';
        }
        return cellvalue;
    }

    function fn_meeting_read(id) {
        loadURL('<%=path%>/com/meeting/read?keyId='+id, $('#page-content'));
    }

    function fn_meeting_cancel(id) {
        __confirm_dialog_input('取消原因', '请输入取消原因', "", function (dialogRef, inputValue) {
            if (inputValue) {
                dialogRef.close();

                fn_meeting_cancel_submit(id, inputValue);
            } else {
                dialogRef.enableButtons();

                __toastr_warning('请输入取消原因');
            }
        });
    }

    function fn_meeting_update(id) {
        loadURL("<%=path%>/com/meeting/input?keyId="+id+"&meet=1",$('#page-content'));
    }

    function fn_meeting_cancel_submit(keyId, reason){
        //ajax执行返回时触发
        var url = '<%=path %>/com/meeting/cancel';
        var data = { keyId: keyId, cancelReason: reason};
        __ajax_post(url, data, function(data){
            __toastr(data);
            if(data.state == 1) {
                $("#meeting_all_table").jqGrid().setGridParam({datatype:'json'}).trigger("reloadGrid");
            }
        });
    }

</script>